package com.vf.admin.client.dao;


import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.WechatPayConfigs;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows10</p>
 *
 * @Author : NemoMeng
 * @Date 2023/6/26 11:28
 */
@Repository
public class WechatPayConfigsDao extends BaseDao<WechatPayConfigs> {

    public List<WechatPayConfigs> listByH5() {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from wechat_pay_configs where pay_type = 1");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, WechatPayConfigs.class);
    }


    public WechatPayConfigs getAppIdInfo(String appIdStr) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from wechat_pay_configs where appId = ?");
        paramList.add(appIdStr);
        String sql = sbStr.toString();
        List<WechatPayConfigs> list = this.queryList(sql, paramList, WechatPayConfigs.class);
        if(ObjectUtil.isNotEmpty(list) && list.size()> 0){
            return list.get(0);
        }
        return null;
    }

    public void openH5(String id) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("update wechat_pay_configs set weight = 0 where pay_type = 1");
        this.update(sbStr.toString(), paramList);

        StringBuilder sbStr2 = new StringBuilder("update wechat_pay_configs set weight=100 where pay_type = 1 and id = "+id);
        this.update(sbStr2.toString(), paramList);
    }

}
